<template>
  <view class="resume-subPage">
    <custom-navbar
      title="在校经历"
      :auto-back="true"
      left-icon-color="#303133"
    />
    <up-gap height="30rpx" />
    <view class="flex items-center justify-end px-24rpx">
      <up-icon :name="Img7" width="25rpx" height="25rpx" />
      <text class="ml-12rpx text-[26rpx] text-[#1f50f2] font-bold">
        新增
      </text>
    </view>
    <up-gap height="30rpx" />
    <view class="block-box">
      <up-cell-group :border="false" :custom-style="{ padding: 0 }">
        <up-cell>
          <template #title>
            <text class="text-[26rpx] text-[#1d2129] font-medium">
              在校部门
            </text>
          </template>
          <template #value>
            <view>
              <up-input v-model="testModel.department" :custom-style="{ border: 'none' }" font-size="26rpx" input-align="right" placeholder="请输入" />
            </view>
          </template>
        </up-cell>
        <up-cell @click="showTime1 = true">
          <template #title>
            <text class="text-[26rpx] text-[#1d2129] font-medium">
              在校时间
            </text>
          </template>
          <template #value>
            <view>
              {{ dateFormat(time1) }}-{{ dateFormat(time2) }}
              <up-datetime-picker :show="showTime1" v-model="time1" mode="datetime" @confirm="confirmTime1"
                @cancel="showTime1 = false"></up-datetime-picker>
              <up-datetime-picker :show="showTime2" v-model="time2" mode="datetime" @confirm="confirmTime2"
                @cancel="showTime1 = false"></up-datetime-picker>
            </view>
          </template>
        </up-cell>
        <up-cell>
          <template #title>
            <text class="text-[26rpx] text-[#1d2129] font-medium">
              担任职务
            </text>
          </template>
          <template #value>
            <view>
              <up-input v-model="testModel.position"  :custom-style="{ border: 'none' }" font-size="26rpx" input-align="right" placeholder="请输入" />
            </view>
          </template>
        </up-cell>
        <view>
          <view class="px-[24rpx] py-[30rpx] pb-20rpx text-[26rpx] text-[#1d2129]">
            工作内容描述
          </view>
          <up-textarea v-model="testModel.content" placeholder="请输入" placeholder-style="font-Size: 26rpx; color:#bebebe;" />
        </view>
      </up-cell-group>
    </view>
    <view>
      <view class="h-190rpx pb-safe" />
      <view
        class="fixed bottom-0 left-0 w-100% flex items-center justify-between bg-#fff px-24rpx pt-24rpx pb-safe"
      >
        <up-button
          :custom-style="{
            background: '#f3f4fa',
            color: '#1D2129',
            width: '338rpx',
            height: '82rpx',
            fontSize: '30rpx',
          }"
          shape="circle"
          text="删除"
        />
        <up-button
          :custom-style="{
            background: '#1f50f2',
            color: '#fff',
            width: '338rpx',
            height: '82rpx',
            fontSize: '30rpx',
          }"
          shape="circle"
          text="确定"
          @click="onClickSubmit"
        />
      </view>
    </view>
    <up-picker :show="show" :columns="columns" key-name="label" @close="close" @confirm="confirm" @cancel="cancel" />
  </view>
</template>

<script setup lang="ts">
import { JobOrInSchoolParams, customerInSchoolAdd } from '@/api/user/customer';
// import Img7 from '@/static/images/userInfo/img-7.png';
const Img7 = "https://yiliao.test03.qcw800.com/static/images/userInfo/img-7.png";
const testModel = ref({
  resume_id: '',   //简历ID
  time: '',
  department: '', //实习/在校 部门
  position: '', //实习/在校 职务
  content: ''  //实习/在校 内容
});
const text = ref('');
const show = ref(false);
const columns = ref([[{ label: '中国' }, { label: '美国' }, { label: '日本' }]]);
const showPicker = () => {
  show.value = true;
};
const close = () => {
  show.value = false;
};
const confirm = ({ value }: { value: Array<{ label: string }> }) => {
  show.value = false;
  testModel.value = value.at(0)!.label;
};
const cancel = () => {
  show.value = false;
};
const showTime1 = ref(false);
  const showTime2 = ref(false);
  const time1 = ref(Date.now());
  const time2 = ref(Date.now());
  const confirmTime1 = (e) => {
    time1.value = e.value
    showTime1.value = false
    showTime2.value = true
  };
  const confirmTime2 = (e) => {
    if (time1.value > e.value) {
      uni.showToast({ title: '结束时间不能小于开始时间', icon: 'none' })
      return
    }
    time2.value = e.value;
    showTime2.value = false;
    testModel.value.time = dateFormat(time1.value) + '-' + dateFormat(time2.value);
  };
  const dateFormat = (time) => {
    if (!time) {
      return ""
    }
    let date = new Date(time);
    let year = date.getFullYear();
    // 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
    let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();


    return year + "." + month;

  }
const resumeId = ref(0)
const onClickSubmit = async () => {
  console.log('简历ID：：：', resumeId.value)
  if (resumeId.value == 0) {
    uni.showToast({title: '简历异常'})
    return
  }
  let obj = {
    ...testModel.value,
    resume_id: resumeId.value,   //简历ID
  }
  // let params:JobOrInSchoolParams = {
  //   resume_id: resumeId.value,   //简历ID
  //   time: '2022.08-2023.05',
  //   department: '', //实习/在校 部门
  //   position: '', //实习/在校 职务
  //   content: ''  //实习/在校 内容
  // }
  console.log('参数：：：', obj)
  let r = await customerInSchoolAdd(obj)
  if (r > 0) {
    console.log('在校经历更新到简历成功  返回上级')
    uni.navigateBack()
  } else {
    uni.showToast({title: '在校经历更新到简历失败'})
  }
}
onLoad((query:any) => {
  if (query.resumeId) {
    console.log('在校经历页获取简历ID', query.resumeId)
    resumeId.value = query.resumeId
  }
})
</script>

<script lang="ts">
export default {
  options: {
    styleIsolation: 'shared',
  },
};

</script>

<style lang="scss" scoped>
.resume-subPage {
  .block-box {
    @apply mx-auto mb-24rpx w-[702rpx] shadow-[0rpx_6rpx_16rpx_0rpx_rgba(191,191,191,0.26)] rounded-[20rpx] bg-#fff p-24rpx pt-0 pb-30rpx;

    :deep(.u-cell__body) {
      @apply px-0 py-12rpx min-h-96rpx;
    }

    :deep(.u-textarea__field) {
      @apply text-26rpx;
    }
  }
}
</style>
